export default {
  data() {
    return {
      baseApi: 'http://www.bliss96998.com/heimamm/public/',
      pagination: {
        pageSizes: [1, 2, 5, 10, 20, 50, 100, 200, 300, 400],
        layout: 'prev, pager, next, total, sizes'
      }
    }
  },
  methods: {
    // 重置表单方法
    formReset({
      formRefName = 'addForm',
      exception = ['pageSize', 'page']
    } = {}) {
      this.$refs[formRefName].resetFields()
      const dataForm = this.dataForm
      Object.keys(dataForm).forEach((key) => {
        if (!exception.includes(key)) {
          dataForm[key] = ''
        }
      })
    },
    // 关闭 dialog 时执行的方法
    // 一般用于关闭新增/编辑表单
    close() {
      this.formReset()
    },

    // 树形结构数据转换
    formatTreeData(
      arr = [],
      pid = '',
      pidKey = 'pid',
      childrenKey = 'children'
    ) {
      return arr.filter((item) => {
        if (item[pidKey] === pid) {
          item[childrenKey] = this.formatTreeData(
            arr,
            item.id,
            pidKey,
            childrenKey
          )
          return true
        }
      })
    },
    // 深拷贝方法
    deepCopy(data) {
      return JSON.parse(JSON.stringify(data))
    }
  }
}
